<template>
  <div class="zong">
    <div class="crumes" v-show="trueOrfal">
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item>首页</el-breadcrumb-item>
        <el-breadcrumb-item :to="{ path: '/' }">{{
          titles
        }}</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div
      class="bannerBox"
      style="width: 1240px; height: 500px; overflow: hidden"
    >
      <Carousel>
        <template>
          <div class="b-p">
            <div class="b-f" v-for="item in bannerData" :key="item.id">
              <div class="b-l" @mouseenter="getId(item.id)" @mouseout="getShow">
                {{ item.name }} {{ item.children[0].name }}
              </div>
              <div class="b-r" v-show="show && id == item.id">
                <p style="padding-left: 20px">分类推荐</p>
                <div class="b-m">
                  <div
                    class="b-m-m"
                    v-for="itemIn in item.goods"
                    :key="itemIn.id"
                  >
                    <img
                      style="width: 100px; height: 100px; padding-right: 3px"
                      :src="itemIn.picture"
                      alt=""
                    />
                    <div>
                      <div>{{ itemIn.name }}</div>
                      <div style="margin: 3px 0; color: gray; font-size: 12px">
                        {{ itemIn.desc }}
                      </div>
                      <div style="color: red; font-size: 18px">
                        ￥ {{ itemIn.price }}
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </template>
      </Carousel>
    </div>
    <div class="titleBox" v-show="trueOrfal">
      <h1>全部分类</h1>
      <ul>
        <li v-for="item in goodsList" :key="item.id" @click="onData(item)">
          <img :src="item.picture" alt="" />
          <p>{{ item.name }}</p>
        </li>
      </ul>
    </div>
    <div
      class="contentBox"
      v-for="item in goodsList"
      :key="item.id"
      v-show="trueOrfal"
    >
      <div class="contentBox-header">
        <h1>- {{ item.name }} -</h1>
        <span>查看全部 ></span>
      </div>
      <ul>
        <li v-for="items in item.goods" :key="items.id">
          <img :src="items.picture" alt="" />
          <p class="p1">{{ items.name }}</p>
          <p class="p2">{{ items.desc }}</p>
          <p class="p3">${{ items.orderNum }}</p>
        </li>
      </ul>
    </div>

    <div class="bigConBox" v-show="!trueOrfal">
      <div class="contBox1">
        <div class="contBoxHeader">
          <p>
            <span class="titles">新鲜好物</span>
            <span class="texts">新鲜出炉 品质靠谱</span>
          </p>
          <p class="alls">查看全部 ></p>
        </div>
        <ul class="newList">
          <li v-for="item in newlists" :key="item.id" @click="onDetail(item)">
            <img :src="item.picture" class="imgs" />
            <p class="imgTitle">{{ item.name }}</p>
            <p class="imgMoney">${{ item.price }}</p>
          </li>
        </ul>
      </div>
      <div class="contBox1">
        <div class="contBoxHeader">
          <p>
            <span class="titles">人气推荐</span>
            <span class="texts">人气爆款 不容错过</span>
          </p>
          <p class="alls"></p>
        </div>
        <ul class="newList">
          <li v-for="item in peopltHotlists" :key="item.id">
            <img :src="item.picture" class="imgs" />
            <p class="imgTitle">{{ item.title }}</p>
            <p class="imgMoney" style="color: gray">{{ item.alt }}</p>
          </li>
        </ul>
      </div>
      <div class="contBox1" style="height: 390px">
        <div class="contBoxHeader">
          <p>
            <span class="titles">热门品牌</span>
            <span class="texts">国际经典 品质保障</span>
          </p>
          <p class="alls">
            <span @click="onright">&lt;</span>
            <span @click="onleft">&gt;</span>
          </p>
        </div>
        <ul class="newListTow" :style="marLeft">
          <li v-for="item in hotPinpai" :key="item.id">
            <img :src="item.picture" class="imgs" />
          </li>
        </ul>
      </div>
      <div class="livingHome" v-for="item in list" :key="item.id">
        <div class="livingHomeHeader">
          <p class="titleP">{{ item.name }}</p>
          <div class="rightDiv">
            <p class="contP">
              <span
                class="active"
                v-for="items in item.children"
                :key="items.id"
                >{{ items.name }}</span
              >
            </p>
            <p style="color: gray">查看全部 ></p>
          </div>
        </div>
        <div class="livingHomeCont">
          <div class="leftDiv">
            <img :src="item.picture" alt="" />
          </div>
          <div class="rightDiv">
            <ul>
              <li
                class="activeLi"
                v-for="itemgoods in item.goods"
                :key="itemgoods.id"
              >
                <div>
                  <img :src="itemgoods.picture" alt="" />
                  <p>{{ itemgoods.name }}</p>
                  <p>{{ itemgoods.desc }}</p>
                  <p style="color: red">￥{{ itemgoods.price }}</p>
                </div>
              </li>
            </ul>
          </div>
        </div>
      </div>
      <div class="bomBox">
        <div class="bomHeader">
          <p class="bomHeaderP1">最新专题</p>
          <p class="bomHeaderP2">查看全部 ></p>
        </div>
        <ul class="bomUl">
          <li class="bomUl_li" v-for="item in bomNewList" :key="item.id">
            <img :src="item.detailsUrl" />
            <div class="topDiv">
              <div class="leftDiv">
                <p class="p1">{{ item.title }}</p>
                <p class="p2">{{ item.summary }}</p>
              </div>
              <div class="rightDiv">￥{{ item.lowestPrice }}起</div>
            </div>
            <div class="bomDiv">
              <p class="span1">
                <img src="@/assets/爱心.png" alt="" />
                <span>{{ item.viewNum }}</span>
              </p>
              <p class="span2">
                <img src="@/assets/眼睛.png" alt="" />
                <span>{{ item.collectNum }}</span>
              </p>
              <p class="span3">
                <img src="@/assets/信息.png" alt="" />
                <span>{{ item.replyNum }}</span>
              </p>
            </div>
          </li>
        </ul>
      </div>
    </div>
  </div>
</template>

<script>
import Carousel from "@/components/Carousel";
export default {
  components: { Carousel },
  data() {
    return {
      id: "100500", //默认显示banner，
      show: false, //二级banner是否显示
      trueOrfal: false, //是否显示
      titles: "", //面包屑标题
      goodsList: [], //分类
      newlists: [], //新鲜好物
      peopltHotlists: [], //人气爆款
      hotPinpai: [], //热门品牌
      marLeft: "", //左边距
      list: [], //服饰母婴等
      bomNewList: [], //最新专题
      bannerData: [],
    };
  },
  name: "zong",
  // async created(){

  // },
  mounted() {
    let _this = this;
    this.bus.$on("goodId", (res) => {
      let obj = {
        id: parseInt(res),
      };
      this.user.getGoodList(obj).then((res) => {
        _this.titles = res.data.result.name; //头部每一项的数据
        _this.goodsList = res.data.result.children;
      });
    });
    this.user.getNewGood().then((res) => {
      _this.newlists = res.data.result;
    });
    this.user.getpeopltHot().then((res) => {
      _this.peopltHotlists = res.data.result;
    });
    this.user.getHotPinpai().then((res) => {
      _this.hotPinpai = res.data.result;
    });
    this.user.getFours().then((res) => {
      _this.list = res.data.result;
    });
    this.user.getnewGoods().then((res) => {
      _this.bomNewList = res.data.result;
    });
  },
  methods: {
    getId(id) {
      this.id = id;
      this.show = true;
    },
    getShow() {
      this.show = false;
    },
    //点击左右按钮
    onright() {
      this.marLeft = "margin-left:0px; transition: all .3s;";
    },
    onleft() {
      this.marLeft = "margin-left:-994px; transition: all .3s;";
    },
    onData(val) {
      console.log(val);
      this.$store.commit("setPageItemData", val);
      this.$router.push({ path: "/home/detailslist", query: { val } });
    },
    //点击商品跳转详情页
    onDetail(item) {
      // console.log(item.id);
      let ids = item.id;
      this.$router.push({ path: "/home/detailpage", params: { id: ids } });
    },
  },
  async created() {
    let _this = this;
    this.bus.$on("shouyeNum", (res) => {
      _this.trueOrfal = res;
    });
    const res = await this.user.getHeaderData();
    this.bannerData = res.data.result;
    console.log(this.bannerData);
  },
};
</script>

<style lang="less" scoped>
.bomBox {
  width: 100%;
  height: 400px;
  margin: 30px auto;
  .bomHeader {
    width: 100%;
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    .bomHeaderP1 {
      font-size: 30px;
    }
    .bomHeaderP2 {
      color: gray;
    }
  }
  .bomUl {
    width: 100%;
    height: 320px;
    display: flex;
    align-items: center;
    justify-content: space-around;
    .bomUl_li {
      width: 390px;
      height: 280px;
      position: relative;
      background: rgba(255, 255, 255, 0.5);
      img {
        width: 390px;
        height: 220px;
      }
      .topDiv {
        width: 100%;
        height: 60px;
        position: absolute;
        bottom: 60px;
        left: 0;
        display: flex;
        align-items: center;
        justify-content: space-around;
        .leftDiv {
          width: 280px;
          height: 100%;
          color: white;
          padding: 8px;
          box-sizing: border-box;
          .p1 {
            width: 100%;
            height: 50%;
            font-size: 19px;
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
          }
          .p2 {
            font-size: 17px;
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
          }
        }
        .rightDiv {
          width: 80px;
          height: 30px;
          background: white;
          color: #cf4444;
          text-align: center;
          line-height: 30px;
        }
      }
      .bomDiv {
        width: 100%;
        height: 60px;
        display: flex;
        align-items: center;
        font-size: 20px;
        font-size: 17px;
        line-height: 30px;
        img {
          width: 20px;
          height: 20px;
        }
        p {
          display: flex;
          align-items: center;
        }
        .span1 {
          margin-left: 10px;
        }
        .span2 {
          margin-left: 30px;
        }
        .span3 {
          margin-left: 160px;
        }
      }
    }
  }
}
.imgs {
  width: 300px;
  height: 300px;
}
.bigConBox {
  .livingHome {
    width: 100%;
    .livingHomeHeader {
      .titleP {
        font-size: 30px;
      }
      width: 100%;
      height: 80px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      .rightDiv {
        width: 500px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        .contP {
          width: 380px;
          display: flex;
          justify-content: space-between;
          span {
            display: block;
            padding: 5px;
            box-sizing: border-box;
            border-radius: 5px;
          }
          .active:hover {
            color: white;
            background: #27ba9b;
          }
        }
      }
    }
    .livingHomeCont {
      width: 100%;
      display: flex;
      .leftDiv {
        width: 240px;
        height: 530px;
        img {
          width: 100%;
          height: 100%;
        }
      }
      .rightDiv {
        width: 1000px;
        height: 530px;
        ul {
          width: 100%;
          height: 100%;
          padding: 10px 20px;
          box-sizing: border-box;
          display: flex;
          flex-wrap: wrap;
          justify-content: space-around;
          li {
            width: 220px;
            height: 260px;
            overflow: hidden;
            div {
              width: 200px;
              height: 250px;
              margin: 10px auto;
              img {
                width: 140px;
                height: 140px;
                display: block;
                margin: 0 auto;
              }
              p {
                width: 200px;
                height: 30px;
                margin: 5px 0;
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
              }
            }
          }
          .activeLi:hover {
            outline: 1px solid #27ba9b;
          }
        }
      }
    }
  }
  width: 100%;
  overflow: hidden;
  .contBox1 {
    margin: 20px 0;
    height: 480px;
    .contBoxHeader {
      width: 100%;
      height: 60px;
      display: flex;
      justify-content: space-between;
      line-height: 60px;
      .titles {
        font-size: 30px;
      }
      .texts {
        font-size: 15px;
        margin-left: 20px;
        color: gray;
      }
      .alls {
        color: gray;
        span {
          padding: 5px;
          box-sizing: border-box;
          margin: 0 5px;
        }
      }
    }
    .newList {
      display: flex;
      justify-content: space-between;
      li {
        width: 300px;
        height: 420px;
        background: #f0f9f4;
        text-align: center;
        line-height: 40px;
        .imgTitle {
          width: 90%;
          height: 40px;
          font-size: 20px;
          overflow: hidden;
          white-space: nowrap;
          text-overflow: ellipsis;
          margin: 0 auto;
        }
        .imgMoney {
          width: 90%;
          height: 40px;
          font-size: 23px;
          overflow: hidden;
          white-space: nowrap;
          text-overflow: ellipsis;
          margin: 0 auto;
          color: rgb(254, 42, 42);
        }
      }
    }
    .newListTow {
      width: 2500px;
      li {
        margin: 9px;
        float: left;
        img {
          width: 230px;
          height: 310px;
        }
      }
    }
  }
}

.crumes {
  height: 40px;
  display: flex;
  align-items: center;
}
.bannerBox {
  width: 1240px;
  height: 500px;
}
.el-carousel__item h3 {
  color: #475669;
  font-size: 14px;
  opacity: 0.75;
  line-height: 150px;
  margin: 0;
}

.el-carousel__item:nth-child(2n) {
  background-color: #99a9bf;
}

.el-carousel__item:nth-child(2n + 1) {
  background-color: #d3dce6;
}
.titleBox {
  width: 1240px;
  height: 300px;
  background: white;
  margin: 40px 0;
  h1 {
    text-align: center;
    line-height: 70px;
    color: gray;
    font-weight: normal;
  }
  ul {
    width: 100%;
    height: 230px;
    display: flex;
    justify-content: flex-start;
    li {
      margin: 0 10px;
      img {
        display: block;
        width: 150px;
        height: 150px;
        margin: 0 auto;
      }
      p {
        text-align: center;
      }
    }
  }
}
.contentBox {
  .contentBox-header {
    width: 100%;
    height: 75px;
    position: relative;
    span {
      position: absolute;
      top: 50%;
      right: 20px;
      transform: translateY(-50%);
      color: rgba(163, 163, 163, 0.727);
    }
  }
  width: 1240px;
  height: 300px;
  background: white;
  margin: 40px 0;
  h1 {
    text-align: center;
    line-height: 70px;
    color: gray;
    font-weight: normal;
  }
  ul {
    width: 100%;
    height: 230px;
    display: flex;
    justify-content: space-evenly;
    li {
      margin: 0 10px;
      img {
        display: block;
        width: 135px;
        height: 135px;
        margin: 0 auto;
      }
      .p1 {
        text-align: center;
        width: 150px;
        height: 22px;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
        margin: 4px 0;
      }
      .p2 {
        text-align: center;
        width: 150px;
        height: 22px;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
        margin: 4px 0;
        color: gray;
        font-size: 12px;
      }
      .p3 {
        text-align: center;
        width: 150px;
        height: 20px;
        margin: 4px 0;
        color: red;
        font-size: 20px;
      }
    }
  }
}

.b-p {
  position: absolute;
  top: 0;
  left: 0;
  background: rgba(0, 0, 0, 0.6);
  color: white;
  padding: 20px 0;
  width: 150px;
  z-index: 1000;
}
.b-l {
  height: 51px;
  line-height: 50px;
  text-align: center;
}
.b-l:hover {
  background: #27ba9b;
}
.b-r {
  background: rgba(255, 255, 255, 0.3);
  text-align: left;
  height: 500px;
  color: black;
  position: absolute;
  top: 0;
  left: 150px;
  width: calc(80vw - 196px);
}
.b-m {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-around;
  height: 420px;
}
.b-m-m {
  width: 29%;
  padding: 0 6px;
  height: 30%;
  display: flex;
  align-items: center;
  background: white;
}
</style>